#ifndef _LIB_PWM_H
#define _LIB_PWM_H

#include <stdint.h>
#include <stdbool.h>

typedef struct _lib_pwm_t lib_pwm_t;

typedef struct 
{
	uint8_t chip;							//PWM线 例如：/sys/class/pwm/pwmchip1/ -> 1
	uint32_t per;							//周期时长 ns
	bool mode_is_normal;			//true 高电平持续时间对应于设定的占空比 false ​低电平持续时间对应于设定的占空比
	float default_duty_cycle;	//默认占空比
}lib_pwm_init_param_t;

/***************************************************************
* Name:   lib_pwm_init()
* Input : param 初始化参数
* Output: void 
* Return: !=NULL 生成的pwm驱动指针
* Author: heweilong
* Revise: V1.0
* Description: 初始化pwm
***************************************************************/
lib_pwm_t* lib_pwm_init(lib_pwm_init_param_t param);

/***************************************************************
* Name:   lib_pwm_destore()
* Input : dev 生成的pwm驱动指针
* Output: void 
* Return: 0 成功 <0 失败(-2 失能pwm失败 -3注销PWM失败)
* Author: heweilong
* Revise: V1.0
* Description: pwm注销
***************************************************************/
int lib_pwm_destore(lib_pwm_t* dev);

/***************************************************************
* Name:   lib_pwm_set_duty()
* Input : dev 生成的pwm驱动指针 duty_cycle 设置的占空比 0~100%
* Output: void 
* Return: 0 成功 -1 失败
* Author: heweilong
* Revise: V1.0
* Description: pwm占空比设置
***************************************************************/
int lib_pwm_set_duty(lib_pwm_t* dev, float duty_cycle);

/***************************************************************
* Name:   lib_pwm_set_duty()
* Input : dev 生成的pwm驱动指针 per 周期时长ns
* Output: void 
* Return: 0 成功 -1 失败
* Author: heweilong
* Revise: V1.0
* Description: pwm周期设置
***************************************************************/
int lib_pwm_set_per(lib_pwm_t* dev, uint32_t per);

/***************************************************************
* Name:   lib_pwm_set_mode()
* Input : dev 生成的pwm驱动指针 is_normal rue 高电平持续时间对应于设定的占空比 false ​低电平持续时间对应于设定的占空比
* Output: void 
* Return: 0 成功 -1 失败
* Author: heweilong
* Revise: V1.0
* Description: pwm工作模式设置
***************************************************************/
int lib_pwm_set_mode(lib_pwm_t* dev, bool is_normal);

#endif